package com.twu.biblioteca;

import java.util.ArrayList;

/**
 * Created with IntelliJ IDEA.
 * User: apple
 * Date: 18/09/13
 * Time: 10:46 PM
 * To change this template use File | Settings | File Templates.
 */
public class BooksRepository {

    ArrayList<Book> books;

    BooksRepository(){
        books=new ArrayList<Book>();
        addBooks();
    }

    public void addBooks(){
        books.add(new Book("Test Driven Development","Kent Beck", "illustrated", "Addison-Wesley", "9780321146533", "Programming"));
        books.add(new Book("Domain-Driven Design", "Eric Evans", "illustrated", "Addison-Wesley", "9780321125217", "Programming" ));
    }

    public String displayRepository(){
        String displayBooks="\nSl.NO\tTitle\t\t\t\tAuthor\t\tEdition\t\tPublisher\t\tISBN\t\t\tCategory";
        displayBooks+="\n*************************************************************************************************";
        for(int i=0;i<books.size();i++){
            displayBooks+="\n"+ (i+1) +"\t" + books.get(i).title + "\t" + books.get(i).author + "\t" + books.get(i).edition + "\t" +
                    books.get(i).publisher + "\t" + books.get(i).isbn + "\t" + books.get(i).category;
        }
        return displayBooks;
    }

    public Book searchBook(String bookName){
        for(Book book:books )
            if(bookName.equals(book.title))
                return book;
        return null;
    }

    public String reserveBook(String bookName){
        String displayReservation=" ";
        if(searchBook(bookName)!=null){
            displayReservation="Thank You! Enjoy The Book";
        }
        else{
            displayReservation="Sorry we don't have that book yet.";
        }
        return displayReservation;

    }
}
